import ContextNames from '../service/ContextNames';
import PreferencesUtil from './PreferencesUtil';

class IndexPageUtil {
  loginPage: string = 'pages/LoginPage/Login';
  mainPage: string = 'pages/MainPage/MainPage';
  token: string = '';

  PageInit(): string {
    let initPage = this.loginPage;
    let tokenValue: string = ''
    PreferencesUtil.getPreferencesValue(ContextNames.H_STORE, 'tokenValue', '').then((value) => {
      tokenValue = value as string;
      console.log('tokenValue:', tokenValue);
      if (tokenValue) {
        this.token = tokenValue;
      }
    }).catch((error) => {
      console.error('error: ' + error)
    })

    if (this.token) {
      initPage = this.mainPage;
    }

    return initPage;
  }
}

const indexPageUtil = new IndexPageUtil();

export default indexPageUtil as IndexPageUtil;